<?php
$ci = &get_instance();
$ci->load->model("Distributivo_Model");
?>


<div id="tabla1" >
    <table class="table  table-striped ">
        <thead>
            <tr>
                <th>PERIODO</th>
                <th>CARRERA</th>
                <th>PENSUM</th>
                <th>CICLO</th>
                <th>Buscar</th>

            </tr>
        </thead>
        <tbody>
            <tr>
                <td>           
                    <div class="control-group">
                        <div class="controls ">
                            <select name="ide_lec" class="span2">
                                <?php
                                foreach ($periodos as $i => $per) {
                                    echo ("<option value='" . $per["ide_lec"] . "'>");
                                    echo ($per["descripcion_lec"] . "</option>");
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                </td>
                <td>            
                    <div class="control-group">
                        <div class="controls ">
                            <select name="ide_car" class="span2"
                                    ONCHANGE="javascript:enviar(this.options[this.selectedIndex].value, '<?php echo (base_url()) . "admin.php/distributivo/inicio" ?>');">
                                        <?php
                                        if ($ide_car == -1)
                                            echo ("<option value='-1' selected>Seleccionar Carrera</option>");
                                        foreach ($carrera as $i => $car) {
                                            echo ("<option value='" . $car["ide_car"] . "'");
                                            echo (($ide_car == $car["ide_car"] ? " selected" : "") . ">");
                                            echo ($car["nombre_car"] . "</option>");
                                        }
                                        ?>
                            </select>

                        </div>
                    </div> </td>
                <td>            
                    <select id="select02" name="ide_pen" class="span2"
                            ONCHANGE="javascript:enviar1('<?php echo (base_url()) . "admin.php/distributivo/inicio" ?>',
                                            '<?php echo $ide_car ?>', this.options[this.selectedIndex].value);">

                        <?php
                        if ($ide_pen == -1)
                            echo ("<option value='-1' selected>Seleccionar Pensum</option>");

                        foreach ($pensum as $i => $pen) {

                            echo ("<option value='" . $pen["ide_pen"] . "'");
                            echo (($ide_pen == $pen["ide_pen"] ? " selected" : "") . ">");
                            echo ($pen["descripcion_pen"] . "-" . $pen["estado_pen"] . "</option>");
                        }
                        ?>

                    </select>


                </td>
                <td>            
                <select id="codigo_cic"  name="codigo_cic" class="span2" autofocus
                        ONCHANGE="javascript:enviar2('<?php echo (base_url()) . "admin.php/distributivo/inicio" ?>',
                                        '<?php echo $ide_car ?>', '<?php echo $ide_pen ?>',
                                        this.options[this.selectedIndex].value);">
                            <?php
                            if ($codigo_cic == -1)
                                echo ("<option value='-1' selected>Seleccionar Ciclo</option>");
                            foreach ($ciclo as $i => $cic) {
                                echo ("<option value='" . $cic["ide_cic"] . "'");
                                echo (($codigo_cic == $cic["ide_cic"] ? " selected" : "") . ">");
                                echo ($cic["codigo_cic"] . "-" . $cic["nombre_cic"] . "</option>");
                            }
                            ?>

                </select>


                </td>

                <td>
                    <div id="buscar"  >
                        <form  action="<?php echo base_url() . "admin.php/distributivo/inicio/$ide_car/$ide_pen/$codigo_cic" ?>" method="post" >
                            <button type="submit" class="btn1" name="btn1" <?php echo ($ide_pen == -1 ? "disabled" : " "); ?>>Buscar</button>
                        </form> 
                    </div>
                </td>

            </tr>
        </tbody>
    </table>        
</div>
<br>
<div id="agregar">
    <form class="well" action="<?php echo base_url() . "admin.php/distributivo/crear" ?>" method="post" >
        <input class="btn" type="submit"  value="Crer Distributivo">
        <?php if($ide_pen>0) {?>
        <a href="<?php echo base_url() . "admin.php/distributivo/vermalla/$ide_pen" ?> " target="_blank">
            <i class="icon-search"></i>Ver Malla</a>
        <?php } ?>


    </form> 
</div>

<legend>CARRERA  <?php echo ((!empty($nom_car) ? $nom_car : " ")); ?></legend>
<?php
if (!empty($nom_car)) {
    $paralelos = array('A', 'B', 'C','D','E',);

    for ($sec = 1; $sec <= 3; ++$sec) {
        for ($semestre = 1; $semestre <= 6; $semestre++) {
            if($semestre == $cod_cic)
            foreach ($paralelos as $par) {
                $materia = $this->Distributivo_Model->getDatosDistributivo($ide_lec, $ide_car, $ide_pen, $semestre, $sec, $par, $ide_mat = null);
                if (!empty($materia)) {
                    ?>

                    <div id="tabla" >
                        <h4>CICLO:  <?php echo ($semestre); ?> 
                                    SECCION:  <?php echo ($sec == 1 ? "DIURNA" : ($sec == 2 ? "NOCTURNA" : "FINES DE SEMANA" )); ?> 
                                    PARALELO : <?php echo ($par); ?></h4>
                        <table class="table table-bordered table-striped table-condensed">
                            <thead>
                                <tr>
                                    <th>COD </th>
                                    <th>MATERIA</th>
                                    <th>CRED</th>
                                    <th>ESTADO</th>
                                    <th>APELLIDOS</th>
                                    <th>NOMBRES</th>

                                    <th colspan="2" align ="center">Acciones</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                foreach ($materia as $i => $row) {
                                    ?>
                                    <tr>
                                        <td><?php echo $row['codigo_mat'] ?></td>
                                        <td><?php echo $row['nombre_mat'] ?></td>
                                        <td><?php echo $row['creditos_mat'] ?></td>
                                        <td><?php echo ($row['estado'] == 0 ? "ACTIVO" : "PENDIENTE"); ?></td>
                                        <td><?php echo $row['apellido_pers'] ?></td>
                                        <td><?php echo $row['nombre_pers'] ?></td>
                                        <td>
                                            <a href='<?php echo (base_url() . "admin.php/distributivo/actualizar/upd/" . $ide_lec . '/' . $ide_car . '/' . $ide_pen . '/' . $row['ide_cic'] . '/' . $sec . '/' . $par . '/' . $row['ide_mat'] . '/' . $row['ide_doc']); ?>'>
                                                <i class="icon-edit"></i>Edit</a>
                                        </td>
                                        <td>
                                            <a href='<?php echo (base_url() . "admin.php/distributivo/actualizar/del/" . $ide_lec . '/' . $ide_car . '/' . $ide_pen . '/' . $row['ide_cic'] . '/' . $sec . '/' . $par . '/' . $row['ide_mat'] . '/' . $row['ide_doc']); ?>'>
                                                <i class="icon-remove"></i>Elim</a></td>

                                    </tr>
                                    <?php
                                }
                                ?>
                            </tbody>
                        </table>        
                    </div>        




                    <?php
                }
            }
        }//for ciclos
    }
}
?>



